package com.qf.action;

import com.qf.utils.ShiroUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class LoginAction {


    @RequestMapping("/doLogin.json")
    public String login(HttpServletRequest request,String username, String password){
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username,password);
        Subject subject = ShiroUtils.getSubject();
        try {
            subject.login(usernamePasswordToken);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("登录失败");
        }
        return "index";

    }

    @RequestMapping("/loginout.json")
    public String logout(HttpServletRequest request){
        ShiroUtils.logout();
        return "redirect:login.html";
    }
}
